package org.example.springbootexperiment03.config;

import org.example.springbootexperiment03.dao.RegionDao;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 * Created by bothin
 * At 2020/5/7 14:30
 * Description: 配置项目中需要的bean
 */
@Configuration
public class BeansConfig {

    @Bean
    public CommandLineRunner commandLineRunner(RegionDao regionDao){
        return args ->{
            regionDao.pullData();
        };
    }

    @Bean
    public RestTemplate restTemplate(ClientHttpRequestFactory factory) {
        return new RestTemplate(factory);
    }

    @Bean
    public ClientHttpRequestFactory simpleClientHttpRequestFactory() {
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setReadTimeout(5000);//单位为ms
        factory.setConnectTimeout(5000);//单位为ms
        return factory;
    }
}
